
//express_demo.js 文件
var express = require('express');
var app = express();

app.post('/api/user', function (req, res) {
    res.set('Content-Type','text/plain');
    console.log(res.get('Content-Type'));

    res.format({
        'text/plain':function()
        {
            res.send('it is text/plain');
        },
        'text/html':function()
        {
            res.send('it is text/html');
        },
        'application/json':function()
        {
           // res.send({messsage:'it is json',else:'it is else'});
           // res.json(null);
            res.status(500).json({messsage:'it is json',else:'it is else'});
        },
        'default':function()
        {
            // res.status(406).send('it is default');
            var filename=req.params.path;
            res.sendfile(filename,options,function(err)
            {
                if(err)
                {

                }
                    cosole.error(err);

            });
        }

    });
    //res.send('Hello World');
    console.log(req.route);
    console.log('oriURL:',req.originalUrl);
    console.log('params:',req.params);
    console.log('from:%s:%s',req.hostname,req.ip);
    console.log('head:',req.get('Content-Type'));
    console.log('head:',req.get('Accept-Encoding'));
    console.log('body:',req.body);
    console.log('cookies',req.cookies);
    console.log('query:',req.query);
})

app.post('/', function (req, res) {
    res.send('Hello World');
    console.log(req.route);
})

var server = app.listen(8888, function () {

    var host = server.address().address
    var port = server.address().port

    console.log("应用实例，访问地址为 http://%s:%s", host, port)

})